import axios from 'axios'

const request = axios.create({
    timeout: 5000
})

// 拦截请求
request.interceptors.request.use((config) => {
    const token = localStorage.getItem('token')

    if (token) {
        config.headers = {
            ...config.headers,
            Authorization: token
        }
    }

    return config
})

request.interceptors.response.use((config) => {
    // 请求成功
    return config.data
}, (err) => {
    return Promise.reject(err)
})


export default request